package cn.itcast.kmean;

public class BinarySearch {
    public static void main(String[] args) {
        int[] arr = {1, 2, 3, 4, 5, 7, 8, 9};
        int target = 6;
        System.out.println(Search(arr, 0, arr.length - 1, target));
    }
    static int temp = -1;
    private static int Search(int[] arr, int low, int high, int target) {

        if (high < low)
            return -1;
        int mid = low +(high-low)/2;
        if (arr[mid] == target) {
            temp = mid;
        } else if (arr[mid] > target) {

            Search(arr, low, mid - 1, target);
        } else if (arr[mid] < target) {
            Search(arr, mid + 1, high, target);
        }
        return temp;
    }
}
